#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;
int T=1;      ///so luong test
int t=0;      ///so lan test hien tai

int charToInt(char c){
    return c-'0';
}

double stringToInt(string s){///chuyen chuoi s -> int
    int temp=0;
    double n=0;
    for(int i=0; i<s.length();i++){
        if(s[i]>='0' && s[i]<='9'){
            temp= charToInt(s[i]);
            n = 10 *n + temp;
        }
    }
    return n;
}

long findGCD(double a, double b){
    while(a!=b)
        if(a>b)
            a=a-b;
        else
            b=b-a;
    return a;
}


char intToChar(int x){
    return (char)(x+'0');
}


string intToString2(unsigned long n){
    string s="";
    while(n!=0){
        s.insert(0,1,intToChar(n%10));
        n=n/10;
    }
    return s;
}

string intToString(double n){
    string s="";
    char str[15];
    sprintf(str,"%.0lf",n);
    s=str;
    return s;
}


string reduceFrac(double tuSo, double mauSo){///ham toi gian phan so tuSo/mauSo
    double UCLN = findGCD(tuSo, mauSo); /// find greatest common divisor
    double tuSo2 = tuSo/UCLN;
    double mauSo2= mauSo/UCLN;

    string s1 = intToString(tuSo2);
    string s2 = intToString(mauSo2);

    string s;
    s= s1+ "/" + s2;
    return s;
}

string convertToFrac2(string in){ //in = a.b1b2..bm(c1c2...cn)
    int pos1=in.find("(");
    long so1=0;
    if(pos1>-1){
        string in1=in.substr(0,pos1);//in1 = a.b1b2...bm
        so1= stringToInt(in1);
    }
    else
        pos1 = in.length();


    long so2= stringToInt(in);

    ///dem so luong so b1...bm
    int pos2=in.find(".");
    double m = pos1-pos2-1;

    double a1;
    ///dem so luong so c1...cn
    int pos3 = in.find(")");
    if(pos3>-1){
        double n = pos3 - pos1 -1;
        a1 = pow(10,n)-1;
    }
    else
        a1=1;


    int tuSo = so2 - so1;


    double a2 = pow(10,m);
    int mauSo = a1*a2;

    return reduceFrac(tuSo,mauSo);
}

double getNumerator(string s){

    double n1=0;
    double n2= stringToInt(s);    ///= ab1b2..bmc1c2...cn

    int pos2=s.find("(");


    if(pos2>-1){        ///neu co dau (
        string s1=s.substr(0,pos2); ///s1 = a.b1b2...bm
        n1= stringToInt(s1);       ///n1 = ab1b2...bm
    }
    return n2 - n1;
}

double getDenominator(string s){
    int pos1=s.find(".");

    int pos2=s.find("(");
    if(pos2==-1)
        pos2= s.length();

    ///dem so luong so b1...bm
    double m = pos2-pos1-1;
    double a1 = pow(10,m);

    ///dem so luong so c1...cn
    double a2;
    int pos3=s.find(")");
    if(pos3>-1){
        double n = pos3 - pos2 -1;
        a2 = pow(10,n)-1;
    }
    else
        a2=1;


    return a1*a2;

}

string convertToFrac(string s){ //in = a.b1b2..bm(c1c2...cn)
    double tuSo = getNumerator(s);
    double mauSo= getDenominator(s);
    return reduceFrac(tuSo,mauSo);
}

int main()
{
    //if(!freopen("input.txt","r",stdin))
        //return 0;
    //if(!freopen("out.txt","w",stdout))
        //return 0;
    cin>>T;
    while(getchar()!='\n');

    string decimal;
    //cout<<decimal.length();
    string out[T];

    while(t<T){
        cin>>decimal;
        out[t]=convertToFrac(decimal);
        t++;
    }

    t=0;
    while(t<T){
        cout<<"Case #"<<t+1<<": "<<out[t]<<endl;
        t++;
    }
    return 0;
}
